package com.itheima.controller;

import com.itheima.Utils.AliyunOssUtils;
import com.itheima.pojo.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件控制器
 * @author GY
 * @version V1.0
 * @date 2025-01-13 9:48
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class FileController {

    private final AliyunOssUtils aliyunOssUtils;

    /**
     * 文件上传
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public Result unload(@RequestParam("file") MultipartFile file){
        log.info("file:{}",file);
        String url = aliyunOssUtils.uploadFile(file);
        log.info("url:{}",url);
        return Result.success(url);
    }
}
